package org.flow.basic.doubts.tjbase.io;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author xl-9527
 * @since 2024/8/30
 */
public class NormalJavaIo implements JavaIo {

    @Override
    public void readFile(final String filePath, final int size) {
        final byte[] bytes = new byte[size == 0 ? 1024 : size];
        try (
                FileInputStream fileInputStream = new FileInputStream(filePath);
                FileOutputStream fileOutputStream = new FileOutputStream(filePath + "io-normal" + System.currentTimeMillis())
        ) {
            while (fileInputStream.read(bytes) != -1) {
                // 执行保存逻辑
                this.writeFile(bytes, fileOutputStream);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void writeFile(final byte[] bytes, final FileOutputStream fileOutputStream) throws IOException {
        fileOutputStream.write(bytes);
    }
}
